package cn.com.open.itembank.sqlprovider;

import cn.com.open.itembank.utils.StringUtil;

import java.util.Map;

/**
 * Created by lucky on 2017/7/17.
 */
public class CourseItemBankSqlProvider {

    private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(CourseItemBankSqlProvider.class);

    /**
     * 根据APPID,机构ID和题库名称，判断是否存在数据sql
     *
     * @param parameter the parameter
     * @return string string
     */
    public String isExistCourseItemBankForInner(Map<String, Object> parameter) {
        String id = (String) parameter.get("id");
        String appKey = (String) parameter.get("appKey");
        String orgid = (String) parameter.get("orgid");
        String name = (String) parameter.get("name");

        StringBuilder sbSql = new StringBuilder();
        sbSql.append("SELECT COUNT(*) FROM CourseItemBank");
        sbSql.append(String.format(" WHERE AppID='%s' AND CreateOrgID='%s' AND CourseName='%s' AND Source = 0", appKey, orgid, name));
        if (!StringUtil.isEmpty(id)) {
            sbSql.append(String.format(" AND ItemBankID <> '%s'", id));
        }

        return sbSql.toString();
    }
}
